package com.hao.tool.web.module.computer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hao.tool.web.module.computer.dto.ApplicationDTO;
import com.hao.tool.web.module.computer.entity.ApplicationInfo;
import com.hao.tool.web.module.computer.mapper.ApplicationMapper;
import com.hao.tool.web.module.computer.service.ApplicationService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * description
 *
 * @author RuiHaoZ on GZ.cmhk
 * @date 2019-11-21 21:45
 */
@Service
public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, ApplicationInfo> implements ApplicationService {


    @Override
    public ApplicationInfo save(ApplicationDTO dto, String userName) {
        ApplicationInfo info = new ApplicationInfo();
        info
                .setId(null)
                .setComId(dto.getComId())
                .setAppName(dto.getAppName())
                .setAppType(dto.getAppType())
                .setEnvType(dto.getEnvType())
                .setAppVersion(dto.getAppVersion())
                .setCreateTime(LocalDateTime.now())
                .setHeartTime(dto.getHeartTime())
                .setLocation(dto.getLocation())
                .setAgentUser(dto.getAgentUser())
                .setCreateUser(userName)
                .setContent(dto.getContent())
                .setComName(null)
                .setComIp(null);
        this.save(info);

        return info;
    }

    @Override
    public List<ApplicationInfo> getByUser(String userName) {
        QueryWrapper<ApplicationInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("AGENT_USER", userName)
                .or().eq("CREATE_USER", userName);
        return list(wrapper);
    }
}
